home *** CD-ROM | disk | FTP | other *** search
- package ms.applet;
-
- import java.applet.Applet;
- import java.applet.AppletContext;
- import java.applet.AppletStub;
- import java.awt.BorderLayout;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.Event;
- import java.awt.Panel;
- import java.io.IOException;
- import java.net.URL;
- import sun.misc.MessageUtils;
-
- public abstract class AppletPanel extends Panel implements AppletStub, Runnable {
- static String propName = "appletloader.";
- Applet applet;
- AppletClassLoader loader;
- protected int status;
- Thread handler;
- public static final int APPLET_DISPOSE = 0;
- public static final int APPLET_LOAD = 1;
- public static final int APPLET_INIT = 2;
- public static final int APPLET_START = 3;
- public static final int APPLET_STOP = 4;
- public static final int APPLET_DESTROY = 5;
- public static final int APPLET_QUIT = 6;
- public static final int APPLET_ERROR = 7;
- public static final int APPLET_RESIZE = 51234;
- public static final int APPLET_LOADING = 51235;
- public static final int APPLET_LOADING_COMPLETED = 51236;
- Dimension appletSize = new Dimension(100, 100);
- // $FF: renamed from: mu sun.misc.MessageUtils
- MessageUtils field_0 = new MessageUtils();
- Thread loaderThread;
- boolean loadAbortRequest = false;
- AppletViewer mAppletViewer;
- Event queue;
- private AppletClassLoader mAppletClassLoader;
-
- public AppletPanel(AppletViewer var1) {
- this.mAppletViewer = var1;
- }
-
- public void init(AppletThreadGroup var1) {
- ((Container)this).setLayout(new BorderLayout());
- String var2 = this.getParameter("width");
- if (var2 != null) {
- Dimension var10000 = this.appletSize;
- Integer var3 = new Integer(Integer.parseInt(var2, 10));
- var10000.width = var3.value;
- }
-
- var2 = this.getParameter("height");
- if (var2 != null) {
- Dimension var7 = this.appletSize;
- Integer var5 = new Integer(Integer.parseInt(var2, 10));
- var7.height = var5.value;
- }
-
- String var6 = "applet-" + this.getParameter("code");
- this.handler = new Thread(var1, this, "thread " + var6);
- this.handler.start();
- }
-
- public Dimension minimumSize() {
- return new Dimension(this.appletSize.width, this.appletSize.height);
- }
-
- public Dimension preferredSize() {
- return this.minimumSize();
- }
-
- public void sendEvent(int var1) {
- this.sendEvent(new Event((Object)null, var1, (Object)null));
- }
-
- protected synchronized void sendEvent(Event var1) {
- if (this.queue == null) {
- var1.target = this.queue;
- this.queue = var1;
- this.notifyAll();
- } else {
- Event var2;
- for(var2 = this.queue; var2.target != null; var2 = (Event)var2.target) {
- }
-
- var2.target = var1;
- }
- }
-
- synchronized Event getNextEvent() throws InterruptedException {
- while(this.queue == null) {
- this.wait(0L);
- }
-
- Event var1 = this.queue;
- this.queue = (Event)this.queue.target;
- var1.target = this;
- return var1;
- }
-
- public void run() {
- Thread var1 = Thread.currentThread();
- if (var1 == this.loaderThread) {
- this.runLoader();
- } else {
- int var2 = var1.priority;
- var1.setPriority(var2 + 1);
-
- while(true) {
- Event var3;
- try {
- var3 = this.getNextEvent();
- } catch (InterruptedException var8) {
- return;
- }
-
- try {
- switch (var3.id) {
- case 0:
- if (this.status == 1) {
- this.status = 0;
- ((Container)this).remove(this.applet);
- }
- break;
- case 1:
- if (this.okToLoad() && this.loaderThread == null) {
- this.setLoaderThread(new Thread(this));
- this.loaderThread.setPriority(var2 + 1);
- this.loaderThread.start();
- Thread var4 = this.loaderThread;
- var4.join(0L);
- this.setLoaderThread((Thread)null);
- }
- break;
- case 2:
- if (this.status == 1) {
- this.applet.resize(this.appletSize);
- this.applet.init();
- ((Container)this).validate();
- this.status = 2;
- this.showAppletStatus(System.getProperty(propName + "inited"));
- }
- break;
- case 3:
- if (this.status == 2) {
- this.applet.resize(this.appletSize);
- this.applet.start();
- ((Container)this).validate();
- this.applet.show();
- this.status = 3;
- this.showAppletStatus(System.getProperty(propName + "started"));
- }
- break;
- case 4:
- if (this.status == 3) {
- this.status = 2;
- this.applet.stop();
- this.showAppletStatus(System.getProperty(propName + "stopped"));
- }
- break;
- case 5:
- if (this.status == 2) {
- this.status = 1;
- this.applet.destroy();
- }
- break;
- case 6:
- return;
- }
- } catch (Exception var9) {
- String var12 = propName + "exception2";
- String var13 = var9.getClass().getName();
- String var14 = ((Throwable)var9).getMessage();
- this.showAppletStatus(MessageUtils.subst(System.getProperty(var12), var13, var14));
- this.showAppletException(var9);
- } catch (ThreadDeath var10) {
- return;
- } catch (Error var11) {
- String var5 = propName + "error2";
- String var6 = var11.getClass().getName();
- String var7 = ((Throwable)var11).getMessage();
- this.showAppletStatus(MessageUtils.subst(System.getProperty(var5), var6, var7));
- this.showAppletException(var11);
- }
-
- this.clearLoadAbortRequest();
- }
- }
- }
-
- private void runLoader() {
- if (this.status == 0) {
- ((Component)this).postEvent(new Event(this, 51235, (Object)null));
- this.status = 1;
-
- try {
- this.loader = this.getClassLoader(this.getCodeBase());
- if (Thread.currentThread().interruptRequested) {
- this.status = 0;
- ((Component)this).postEvent(new Event(this, 51236, (Object)null));
- return;
- }
- } catch (IOException var22) {
- this.status = 7;
- this.showAppletStatus(((Throwable)var22).getMessage());
- this.showAppletLog(((Throwable)var22).getMessage());
- this.showAppletException(var22);
- ((Component)this).postEvent(new Event(this, 51236, (Object)null));
- return;
- }
-
- String var1 = this.getParameter("code");
- if (var1 == null) {
- String var2 = propName + "nocode";
- this.status = 7;
- this.showAppletStatus(System.getProperty(var2));
- this.showAppletLog(var2);
- ((Component)this).repaint();
- } else if (var1.startsWith(".class", var1.count - ".class".count)) {
- var1 = var1.substring(0, var1.count - 6).replace('/', '.');
- } else if (var1.startsWith(".java", var1.count - ".java".count)) {
- var1 = var1.substring(0, var1.count - 5).replace('/', '.');
- }
-
- label175: {
- try {
- String var4 = propName + "loading";
- this.showAppletStatus(MessageUtils.subst(System.getProperty(var4), var1));
- this.applet = (Applet)this.loader.loadClass(var1).newInstance();
- if (!Thread.currentThread().interruptRequested) {
- break label175;
- }
-
- this.status = 0;
- this.applet = null;
- return;
- } catch (ClassNotFoundException var15) {
- this.status = 7;
- String var25 = propName + "notfound";
- var25 = MessageUtils.subst(System.getProperty(var25), var1);
- this.showAppletStatus(var25);
- this.showAppletLog(var25);
- this.showAppletException(var15);
- } catch (InstantiationException var16) {
- this.status = 7;
- this.showAppletException(var16);
- return;
- } catch (IllegalAccessException var17) {
- this.status = 7;
- this.showAppletException(var17);
- return;
- } catch (Exception var18) {
- this.status = 7;
- String var24 = propName + "exception";
- String var27 = ((Throwable)var18).getMessage();
- this.showAppletStatus(MessageUtils.subst(System.getProperty(var24), var27));
- this.showAppletException(var18);
- return;
- } catch (ThreadDeath var19) {
- this.status = 7;
- return;
- } catch (Error var20) {
- this.status = 7;
- String var5 = propName + "error";
- String var6 = ((Throwable)var20).getMessage();
- this.showAppletStatus(MessageUtils.subst(System.getProperty(var5), var6));
- this.showAppletException(var20);
- return;
- } finally {
- ((Component)this).postEvent(new Event(this, 51236, (Object)null));
- }
-
- return;
- }
-
- Applet var23 = this.applet;
- var23.stub = this;
- this.applet.hide();
- ((Container)this).add("Center", this.applet);
- this.showAppletStatus(System.getProperty(propName + "loaded"));
- ((Container)this).validate();
- }
- }
-
- protected synchronized void stopLoading() {
- if (this.loaderThread != null) {
- this.loaderThread.interrupt();
- } else {
- this.setLoadAbortRequest();
- }
- }
-
- protected synchronized boolean okToLoad() {
- return !this.loadAbortRequest;
- }
-
- protected synchronized void clearLoadAbortRequest() {
- this.loadAbortRequest = false;
- }
-
- protected synchronized void setLoadAbortRequest() {
- this.loadAbortRequest = true;
- }
-
- private synchronized void setLoaderThread(Thread var1) {
- this.loaderThread = var1;
- }
-
- public boolean isActive() {
- return this.status == 3;
- }
-
- public void appletResize(int var1, int var2) {
- }
-
- public Applet getApplet() {
- return this.applet;
- }
-
- protected void showAppletStatus(String var1) {
- String var2 = System.getProperty(var1);
- if (var2 == null) {
- var2 = var1;
- }
-
- this.getAppletContext().showStatus(var2);
- }
-
- protected void showAppletLog(String var1) {
- String var2 = System.getProperty(var1);
- if (var2 == null) {
- var2 = var1;
- }
-
- System.out.println(var2);
- }
-
- protected void showAppletException(Throwable var1) {
- var1.printStackTrace();
- ((Component)this).repaint();
- }
-
- synchronized AppletClassLoader getClassLoader(URL var1) throws IOException {
- if (this.mAppletClassLoader == null) {
- String var2 = var1.file;
- if (var2.startsWith("/", var2.count - "/".count)) {
- this.mAppletClassLoader = new AppletClassLoader(this.mAppletViewer, var1);
- } else {
- this.mAppletClassLoader = new AppletZipClassLoader(this.mAppletViewer, var1);
- }
- }
-
- return this.mAppletClassLoader;
- }
-
- public abstract URL getDocumentBase();
-
- public abstract URL getCodeBase();
-
- public abstract String getParameter(String var1);
-
- public abstract AppletContext getAppletContext();
- }
-